Skip to content

Conversation

@foxtran
Copy link
Member

@foxtran foxtran commented Jul 22, 2025

Fixes #149771

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jul 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2025

@llvm/pr-subscribers-flang-semantics

Author: foxtran (foxtran)

Changes

Fixes #149771


Full diff: https://github.com/llvm/llvm-project/pull/149973.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+7)
  • (added) flang/test/Semantics/declarations09.f90 (+11)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index a2f2906af10b8..a99a65b0dc0b4 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -66,6 +66,7 @@ class CheckHelper {
   void CheckVolatile(const Symbol &, const DerivedTypeSpec *);
   void CheckContiguous(const Symbol &);
   void CheckPointer(const Symbol &);
+  void CheckExternal(const Symbol &);
   void CheckPassArg(
       const Symbol &proc, const Symbol *interface, const WithPassArg &);
   void CheckProcBinding(const Symbol &, const ProcBindingDetails &);
@@ -983,6 +984,7 @@ void CheckHelper::CheckObjectEntity(
     }
   }
   if (symbol.attrs().test(Attr::EXTERNAL)) {
+    CheckExternal(symbol);
     SayWithDeclaration(symbol,
         "'%s' is a data object and may not be EXTERNAL"_err_en_US,
         symbol.name());
@@ -2460,6 +2462,11 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852
   }
 }
 
+void CheckHelper::CheckExternal(const Symbol &symbol) {
+  CheckConflicting(symbol, Attr::EXTERNAL, Attr::INTRINSIC); // F'2023 C842
+  CheckConflicting(symbol, Attr::EXTERNAL, Attr::PARAMETER);
+}
+
 // C760 constraints on the passed-object dummy argument
 // C757 constraints on procedure pointer components
 void CheckHelper::CheckPassArg(
diff --git a/flang/test/Semantics/declarations09.f90 b/flang/test/Semantics/declarations09.f90
new file mode 100644
index 0000000000000..4bd08a1749721
--- /dev/null
+++ b/flang/test/Semantics/declarations09.f90
@@ -0,0 +1,11 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
+
+subroutine bug149771
+
+  !ERROR: 'x1' may not have both the EXTERNAL and INTRINSIC attributes
+  integer, external, intrinsic :: x1
+
+  !ERROR: 'x2' may not have both the EXTERNAL and PARAMETER attributes
+  integer, external, parameter :: x2
+
+end subroutine bug149771

@foxtran foxtran closed this Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flang] external must conflict with intrinsic and vice versa

2 participants